import express from "express";
import mysql from "mysql2/promise";

const router = express.Router();

router.post("/", async (req, res) => {
  try {
    const { type, ...connectionConfig } = req.body;
    const conn = await mysql.createConnection(connectionConfig);
    await conn.ping();
    await conn.end();
    res.json({ success: true, message: "数据库连接成功！" });
  } catch (error) {
    res.json({ success: false, message: `连接失败: ${error.message}` });
  }
});

export default router;